<template>
  <div id="page-wechat-view">
    <h2>微信对接配置</h2>
    <Card :bordered="false">
      <Row>
        <Col span="20" offset="2">
          <Form :model="form" :label-width="200" class="mt20">
            <FormItem label="微信公众账号(应用ID)：">
              {{ form.wechatAppId }}
            </FormItem>
            <FormItem label="应用秘钥：">
              {{ form.wechatSecret }}
            </FormItem>
            <FormItem label="用户信息回调地址：">
              {{ form.backUrl }}
            </FormItem>
            <FormItem label="Token(令牌)：">
              {{ form.wechatToken }}
            </FormItem>
            <FormItem label="推送消息模板ID：">
              {{ form.pushNoticeTlpid }}
            </FormItem>
            <FormItem>
              <Button type="primary" @click="goUpdate()">编辑</Button>
            </FormItem>
          </Form>
        </Col>
      </Row>
    </Card>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import wechatApi from '@/api/wechat'

  export default {
    data () {
      return {
        form: {
        }
      }
    },
    computed: {
      ...mapGetters({
        userInfo: 'userInfo'
      })
    },
    methods: {
      async detail () {
        const { body } = await wechatApi.getSetting({ pkRcId: this.userInfo.pkRclubInfo })
        if (this.$apiHelper.requestSuccessed(body.responseCode)) {
          this.form = body.responseData
        } else {
          setTimeout(() => {
            this.$Modal.error({
              title: '错误',
              content: body.desc,
              onOk: () => {}
            })
          }, 500)
        }
      },
      goUpdate () {
        this.$router.push({path: '/wechat/setting'})
      }
    },
    mounted () {
      this.$store.dispatch('getUserInfo')
      this.detail()
    }
  }
</script>
